<template>
	<view class="changecore">
		<view class="ag-topbg"></view>
		<view style="height: 113rpx;"></view>
		<view class="changecore-card">
			<view class="changecore-card__head">
				<image src="../../static/img/icon-refresh.png" />
				<text>更换滤芯</text>
			</view>
			<view class="inputrow">
				<view class="inputrow__label">滤芯类型：</view>
				<input :disabled="true" :value="maintainInfo.AppBrief" />
			</view>
			<!-- <AGInput readonly  :value="maintainInfo.AppBrief" /> -->
			<view class="changecore-card__switch">
				<text >更换客户自购件</text>
				<switch color="#3d85db"  :disabled="IsDisabledReplacePurchasedByOneself" :checked="IsReplacePurchasedByOneself" @change="ChangeReplacePurchased" />
			</view>
			<view class="changecore-card__row">
				<AGInput dropdown disabled placeholder="请扫描或选择更换件" :value="maintainInfo.PartsNum" @dropDownClick="openMaintainSearch" />
				<view class="changecore-card__scanbtn" @click="openBatchMaintainPart">
					<image src="../../static/img/icon-qrcode-color.png" />
				</view>
			</view>
			<view class="changecore-card__tip" >
				更换件：{{maintainInfo.PartsName}}
			</view>
			<view class="changecore-card__pictags">
				<image :src="maintainInfo.Img" />
				<view>
					<view class="ag-status-tag primary"><text style="font-size: 18px;">零售价: {{maintainInfo.Price}}</text></view>
					<view class="ag-status-tag primary"><text style="font-size: 18px;">网点库存: {{maintainInfo.SiteStock}}</text></view>
					<view class="ag-status-tag primary"><text style="font-size: 18px;">保养周期: {{maintainInfo.MaintainPeriod}}</text></view>
				</view>
			</view>
			<view class="bg-grey" v-if="maintainInfo.SiteStock==0?true:false">换件网点库存为0，可能会影响工单完工成功！</view>
			<view class="changecore-card__footer">
				<button class="cu-btn lg primary block" @click="onConfirm">确定</button>
				<button class="cu-btn lg primary block plain" @click="onCancel">取消</button>
			</view>
		</view>
		<view class="ag-spacer30"></view>
	</view>
</template>
<script>
	import AGInput from '@/components/AGInput';
	import changecorebehavior from './changecorebehavior';
	export default {
		mixins: [changecorebehavior],
		components: {
			AGInput
		},
		data() {
			return {
				mindex: '',
				PartsNum: '',
				proIndex:'',
				orderDetailId: "",
				//maintainItem:{},
				IsDisabledReplacePurchasedByOneself:false,
				IsReplacePurchasedByOneself:false,
				maintainInfo:{},
			}
		},
		onLoad(e) {
			uni.showLoading({
				title:"加载中..",
				mask:true,
			});
			//选择更换滤芯
			uni.$on('selectmaintainPartItem',(e)=>{
				console.log("滤芯类型：",e);
				this.maintainInfo = e;
				console.log("滤芯类型2：",this.maintainInfo);
				this.maintainInfo.Img = e.base64Img;
			});
			let {
				parm
			} = e;	
			let parms = JSON.parse(decodeURIComponent(parm));
			this.orderDetailId = parms.WoId;
			//this.maintainItem = JSON.parse(decodeURIComponent(maintainItem));
			// console.log(this.maintainItem.FilterPartNum);
			// console.log(this.maintainItem);
			this.PartsNum = parms.PartsNum;
			this.IsDisabledReplacePurchasedByOneself = parms.IsDisabledReplacePurchasedByOneself;
			this.IsReplacePurchasedByOneself = parms.IsReplacePurchasedByOneself
			this.mindex = parms.mindex;
			this.proIndex = parms.proIndex;
			console.log(parms);
			//console.log(this.partsNum);
			//获取保养信息
			this.GetMaintainPartInfo();
		},
		onUnload(e){
			uni.$off('selectmaintainPartItem');
		},
		methods: {
			//点击更换滤芯
			//打开滤芯扫描
			openBatchMaintainPart(e){
				console.log("打开批量扫描滤芯");	
				uni.scanCode({
					scanType: 'barCode',
					success: (res) => {
						//console.log('条码类型：' + res.scanType);
						//console.log('条码内容：' + res.result);
						this.PartsNum = res.result;
						uni.showLoading({
							mask: true,
						});
						this.GetMaintainPartInfo();
					},
				});
			},
			//确认
			onConfirm(e){
				this.maintainInfo.IsReplacePurchasedByOneself = this.IsReplacePurchasedByOneself;
				let parm = {
					proIndex:this.proIndex,
					mindex:this.mindex,
					maintainItem:this.maintainInfo,
				}
				uni.$emit("onConfirm",parm);
				uni.navigateBack();
			},
			//取消
			onCancel(e){			
				let parm = {
					proIndex:this.proIndex,
					mindex:this.mindex,
					IsReplaceFilterPart:false,
				}
				uni.$emit("onCancel",parm);
				uni.navigateBack();
			},
			//更改自购件
			ChangeReplacePurchased(e){
				this.IsReplacePurchasedByOneself = !this.IsReplacePurchasedByOneself;
			},
			//打开更换滤芯搜索
			openMaintainSearch(e){
				debugger;
				uni.navigateTo({
					url:"../wocomplete/maintainpartsearch/maintainpartsearch?woId="+this.orderDetailId
				})
			}
		},
	}
</script>
<style lang="scss">
	@import "./index.scss";
</style>
